<template>
  <div class="dashboard-container">
    <component :is="currentRole" />
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import adminDashboard from './admin'
import editorDashboard from './editor'
import {getInfo} from "@/api/user";

export default {
  name: 'Dashboard',
  components: { adminDashboard, editorDashboard },
  data() {
    return {
      currentRole: 'adminDashboard',
      joinFS:null,
    }
  },
  computed: {
    ...mapGetters([
      'roles',
      'token',
      'isNeedJoinFirstSelect',
    ])
  },
  watch:{
    joinFS(val){
      if (val ===1 ){
        this.$alert('需要参加初始等级考试', '新员工您好', {
          confirmButtonText: '确定',
          callback: action => {
            this.$router.push({
              name :"examIndex",
              query:{
                testType:1
              }
            })
          }
        });
      }
    }
  },
  created() {
    this.getUserInfo();
    if (!this.roles.includes('admin')) {
      this.currentRole = 'editorDashboard'
    }
  },
  methods:{
    getUserInfo() {
      getInfo(this.token).then(res => {
        if (res.code===20000){
          this.joinFS = res.data.isNeedJoinFirstSelect;
        }
      })
    }
  }
}
</script>

